/*
 * Copyright (c) 2009.
 * nick@tmro.net
 */
package net.tmro.loko.ejb.dao.jpa.category;

import net.tmro.loko.domain.category.Category;
import net.tmro.loko.ejb.dao.CategoryDao;
import net.tmro.loko.ejb.dao.jpa.JpaDao;

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.persistence.Query;
import java.util.Date;
import java.util.List;

@Stateless(name = "CategoryBean")
@Local(value = {CategoryDao.class})
public class CategoryJpaDao extends JpaDao<Long, Category> implements CategoryDao {

    /**
     * @see net.tmro.loko.ejb.dao.CategoryDao#findNewCategories(java.util.Date)
     */
    public List<Category> findNewCategories(Date dateSince) {
        Query q = entityManager.createQuery("SELECT e FROM Category e " +
                "WHERE e.dateCreated >= :date_since");
        q.setParameter("date_since", dateSince);

        return (List<Category>) q.getResultList();
    }
}